home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 1.iso / toolbox / src / demos / OpenGL / backtrace / Unitdisk.h < prev   
C/C++ Source or Header  |  1996-11-11  |  6KB  |  174 lines

  1. /*
  2.  * (c) Copyright 1993, Silicon Graphics, Inc.
  3.  * ALL RIGHTS RESERVED 
  4.  * Permission to use, copy, modify, and distribute this software for 
  5.  * any purpose and without fee is hereby granted, provided that the above
  6.  * copyright notice appear in all copies and that both the copyright notice
  7.  * and this permission notice appear in supporting documentation, and that 
  8.  * the name of Silicon Graphics, Inc. not be used in advertising
  9.  * or publicity pertaining to distribution of the software without specific,
  10.  * written prior permission. 
  11.  *
  12.  * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
  13.  * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
  14.  * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
  15.  * FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL SILICON
  16.  * GRAPHICS, INC.  BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
  17.  * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
  18.  * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
  19.  * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
  20.  * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC.  HAS BEEN
  21.  * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
  22.  * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
  23.  * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
  24.  * 
  25.  * US Government Users Restricted Rights 
  26.  * Use, duplication, or disclosure by the Government is subject to
  27.  * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
  28.  * (c)(1)(ii) of the Rights in Technical Data and Computer Software
  29.  * clause at DFARS 252.227-7013 and/or in similar or successor
  30.  * clauses in the FAR or the DOD or NASA FAR Supplement.
  31.  * Unpublished-- rights reserved under the copyright laws of the
  32.  * United States.  Contractor/manufacturer is Silicon Graphics,
  33.  * Inc., 2011 N.  Shoreline Blvd., Mountain View, CA 94039-7311.
  34.  *
  35.  * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
  36.  */
  37. #ifndef UNITDISK_H
  38. #define UNITDISK_H
  39.  
  40. #include "Color.h"
  41. #include "Point.h"
  42.  
  43. /* Disks are sort of like spheres that have been flattened into
  44.  * the xy plane without changing the normals */
  45.  
  46. /* They are always made up of quadrilaterals */
  47.  
  48. class Unitdisk {
  49.  public:
  50.   Unitdisk();
  51.   ~Unitdisk();
  52.  
  53.   inline Unitdisk operator=(Unitdisk a);
  54.  
  55.   void draw();
  56.   void draw_by_perimeter(int pass_colors = 0, 
  57.              int pass_norms = 0, 
  58.              int pass_tex = 0);
  59.  
  60.   void set_divisions(int new_rdivisions, int new_tdivisions);
  61.   int get_rdivisions();
  62.   int get_tdivisions();
  63.   
  64.   /* How big the section of the sphere is */
  65.   void set_angle(float new_angle);
  66.   GLfloat get_angle();
  67.  
  68.   /* This comes from the angle */
  69.   GLfloat get_radius();
  70.  
  71.   /* Allocate points to hold the right number of things */
  72.   void alloc_points();
  73.   void alloc_normals();
  74.   void alloc_points_normals();
  75.   void free_points();
  76.   void free_normals();
  77.   void free_points_normals();
  78.  
  79.   /* Fill the points / normals with the appropriate sin and cos values */
  80.   void fill_points();
  81.   void fill_normals();
  82.   void fill_points_normals();
  83.  
  84.   /* These are mallocing */
  85.   void copy_points(Unitdisk src);
  86.   void copy_normals(Unitdisk src);
  87.   void copy_normals_from_points(Unitdisk src);
  88.   void copy_normals_from_points();
  89.  
  90.   /* These transform all the points */
  91.   void translate(Point trans);
  92.   void scale(float s);
  93.   void scale_translate(float s, Point trans);
  94.  
  95.   /* Project all points into xy plane along normal or through projpt */
  96.   void project();
  97.   void project_borrow_points(Unitdisk src);
  98.   void project(Point projpt);
  99.  
  100.   /* Change all normals from their original direction (NOT their current
  101.    * direction) to refracted direction.  Normals do not have to be computed
  102.    * before calling this. However, the disk must still be in the xy plane
  103.    * and the light must be on the z axis*/
  104.   void refract_normals(Point light, float I);
  105.  
  106.   /* Points the disk (meaning the normal at the center of the disk)
  107.    * in direction d */
  108.   void face_direction(Point d);
  109.   void face_direction(Point d, Unitdisk src);
  110.  
  111.   
  112.   /* Allocate colors */
  113.   void alloc_colors();
  114.   void free_colors();
  115.  
  116.   void set_colors(Color c);
  117.   void add_colors(Color c);
  118.  
  119.   void map_normals_to_colors();
  120.   void map_z_to_colors();
  121.   void scale_colors_by_z();
  122.   void scale_alpha_by_z();
  123.   void scale_colors_by_normals(Point light);
  124.   void scale_colors_by_normals(Point light, Unitdisk src_normals);
  125.   void scale_colors_by_points(Point light, Unitdisk src_points);
  126.   /* Computes how much the area of a section differs from the corresponding
  127.    * section in disk and scales the color by this amount.*/
  128.   void scale_colors_by_darea(Unitdisk disk);
  129.   
  130.  
  131.  private:
  132.   int rdivisions, tdivisions;
  133.   Point *points, *normals;
  134.   int points_size, normals_size;
  135.   Color *colors;
  136.   int colors_size;
  137.   Point sphere;
  138.   GLfloat angle;
  139.   Point zaxis;
  140.   int still_in_xy;
  141.  
  142.   float *sintable, *costable;
  143.  
  144.   void draw_nocolors();
  145.   void draw_colors_normals();
  146.   void draw_colors_nonormals();
  147.   void scale_colors_by_either(Point dlight, Point *what);
  148.   int get_npoints();
  149.   void copy_either(Point *dpt, Point *spt);
  150.   void fill_either(Point *what);
  151.   void fill_points_strip1();
  152.   void fill_normals_strip1();
  153.   void fill_either_strip1(Point *what);
  154.   void fill_trig_tables();
  155.   inline float Unitdisk::area_triangle(Point a, Point b, Point c);
  156.   inline float Unitdisk::area_triangle(GLfloat *a, GLfloat *b, GLfloat *c);
  157.   inline float Unitdisk::area_2triangle(GLfloat *a, GLfloat *b, GLfloat *c);
  158. };
  159.  
  160. inline Unitdisk Unitdisk::operator=(Unitdisk a)
  161. {
  162.   rdivisions = a.rdivisions;
  163.   tdivisions = a.tdivisions;
  164.   points = a.points;
  165.   normals = a.normals;
  166.   colors = a.colors;
  167.   sphere = a.sphere;
  168.   angle = a.angle;
  169.   zaxis = a.zaxis;
  170.   return *this;
  171. }
  172.  
  173. #endif 
  174.